package com.itheima.tlias84.aop.cglib;

import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * 创建方法拦截器：实现MethodInterceptor接口
 */
public class EatInterceptor implements MethodInterceptor {
    @Override
    public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
        //增强部分
        System.out.println("洗手");
        //调用父类的方法:相当于super.eat()
//        method.invoke(obj);
        Object object = proxy.invokeSuper(obj, args);
        //增强部分
        System.out.println("刷牙");

        return object;
    }
}
